package com.example.homework02.controller;


import com.niit.homework02.entity.Student;
import com.niit.homework02.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 简单学生信息表(Student)表控制层
 *
 * @author
 * @since 2022-03-29 17:42:04
 */
@Controller
@RequestMapping("/student")
public class StudentController {
    /**
     * 服务对象
     */
    @Resource(name = "studentService")
    private StudentService studentService;

    /**
     * 使用表单提交 新增数据 后端直接使用对象接收也可以
     * 要求属性与key保持一致
     *
     * @param student 实体
     * @return 新增结果
     */
    @RequestMapping("/add")
    public String add(Student student, Model model) {

        int flag = studentService.insert(student);
        if (flag > 0) {
            model.addAttribute("flag", "插入成功!");
            return "success";
        }
        model.addAttribute("flag", "插入失败!");

        return "fail";
    }



}

